package com.chengcang.admin.modules.busi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chengcang.admin.modules.busi.dto.BusiAddressDTO;
import com.chengcang.admin.modules.busi.dto.BusiInvoiceHeadDTO;
import com.chengcang.admin.modules.busi.entity.BusiDemandAddressSnapshotEntity;
import com.chengcang.admin.modules.busi.service.BusiInvoiceHeadService;
import com.chengcang.common.service.impl.CrudServiceImpl;
import com.chengcang.admin.modules.busi.dao.BusiDemandInvoiceHeadSnapshotDao;
import com.chengcang.admin.modules.busi.dto.BusiDemandInvoiceHeadSnapshotDTO;
import com.chengcang.admin.modules.busi.entity.BusiDemandInvoiceHeadSnapshotEntity;
import com.chengcang.admin.modules.busi.service.BusiDemandInvoiceHeadSnapshotService;
import com.chengcang.common.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 发票抬头
 *
 * @author Zhanli xy321231@163.com
 * @since 1.0.0 2023-02-20
 */
@Service
public class BusiDemandInvoiceHeadSnapshotServiceImpl extends CrudServiceImpl<BusiDemandInvoiceHeadSnapshotDao, BusiDemandInvoiceHeadSnapshotEntity, BusiDemandInvoiceHeadSnapshotDTO> implements BusiDemandInvoiceHeadSnapshotService {


    @Autowired
    private BusiInvoiceHeadService busiInvoiceHeadService;

    @Override
    public QueryWrapper<BusiDemandInvoiceHeadSnapshotEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<BusiDemandInvoiceHeadSnapshotEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public BusiDemandInvoiceHeadSnapshotEntity saveDemandSnapshot(Long demandId, Long invoiceHeadId) {
        BusiInvoiceHeadDTO dto = busiInvoiceHeadService.get(invoiceHeadId);
        BusiDemandInvoiceHeadSnapshotEntity entity = ConvertUtils.sourceToTarget(dto, BusiDemandInvoiceHeadSnapshotEntity.class);
        entity.setId(null);
        entity.setInvoiceHeadId(invoiceHeadId);
        entity.setDemandId(demandId);
        this.insert(entity);
        return entity;
    }


}